package com.caojing.syby.ui.tenbuy;


import android.graphics.Color;
import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.caojing.syby.R;
import com.caojing.syby.ui.tenbuy.tenbuysharefragment.TenbuyShareFragment;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * A simple {@link Fragment} subclass.
 */
public class TenbuyFragment extends Fragment {
    @Bind(R.id.tablayout_tenbuy)
    TabLayout tablayoutTenbuy;
    @Bind(R.id.viewpager_tenbuy)
    ViewPager viewpagerTenbuy;

    private String[]tabNames;
    private int [] channels={9,3,4,5};
    private List<TenbuyShareFragment> shareFragmentList=new ArrayList<>();

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_tenbuy, container, false);
        ButterKnife.bind(this, view);
        initData();


        return view;
    }

    private void initData() {

        //设置指示器的颜色
        tablayoutTenbuy.setSelectedTabIndicatorColor(Color.RED);
        //设置tab的文本颜色
        tablayoutTenbuy.setTabTextColors(Color.BLACK,Color.RED);

        //设置mode 滚动模式动态改变tabLayout宽度
//        tablayoutTenbuy.setTabMode(TabLayout.MODE_SCROLLABLE);
        tablayoutTenbuy.setTabMode(TabLayout.MODE_FIXED);

        tablayoutTenbuy.getTabGravity();


        tabNames=getResources().getStringArray(R.array.tabNames);

        for (int i=0;i<tabNames.length;i++){
            TenbuyShareFragment shareFragment= TenbuyShareFragment.newInstance(channels[i]+"");
            shareFragmentList.add(shareFragment);

        }



        TenbuyViewpagerAdapter adapter=new TenbuyViewpagerAdapter(getChildFragmentManager(),shareFragmentList,tabNames);
        viewpagerTenbuy.setAdapter(adapter);
        //将tablayout和viewpager关联在一起
        tablayoutTenbuy.setupWithViewPager(viewpagerTenbuy);


    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        ButterKnife.unbind(this);
    }

}
